package com.project.service.impl;

import com.project.bean.LogBean;
import com.project.bean.UserBean;
import com.project.mapper.ILogMapper;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalTime;
import java.util.List;
@Service //申明该类为业务组件类
@Transactional //该类中所有方法，需要进行事务管理
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper mapper;
    @Override
    public void addUser(UserBean userBean) {
        mapper.addUser(userBean);
    }

    @Override
    public void delUser(int userId) {
        mapper.delUser(userId);
    }

    @Override
    public void updateLevel(int userId, String level) {
        mapper.updateLevel(userId, level);
    }

    @Override
    public List<UserBean> findByItem(String level) {
        return mapper.findByItem(level);
    }

    @Override
    public UserBean login(String userName, String pwd) {
        UserBean user = mapper.login(userName, pwd);
        LogBean log = new LogBean("用户"+user.getName()+"在"+ LocalTime.now()+"登录系统");
        if (user!=null){
            mapper.addLog(log);
        }
        return user;
    }

    @Override
    public UserBean findById(int userId) {
        return mapper.findById(userId);
    }

    @Override
    public void updatePwd(int id, String newPwd) {
        mapper.updatePwd(id, newPwd);
    }


}
